package cn.tedu.baidashi.service.Impl;

import cn.tedu.baidashi.mapper.AddressMapper;
import cn.tedu.baidashi.mapper.CustomerMapper;
import cn.tedu.baidashi.model.Customer;
import cn.tedu.baidashi.service.ICustomerService;
import cn.tedu.baidashi.vo.CustomerVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tedu.cn
 * @since 2022-02-12
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
    private List<Customer> customers=new CopyOnWriteArrayList<>();
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    AddressMapper addressMapper;
    //查询顾客的所有对象，查询条件为null
    @Override
    public List<Customer> getAll() {
        if(customers.isEmpty()){
            synchronized (customers){
                customers.clear();
                List<Customer> list=customerMapper.selectList(null);
                customers.addAll(list);
                System.out.println("customers加载数据完成");

            }
        }
        return customers;
    }
    //通过传入顾客的名称写getCustomerVO对象的方法
    @Override
    public CustomerVo getCustomerVo(String customer_name) {
        Customer customer=customerMapper.findCustomerByCustomerName(customer_name);
        CustomerVo customerVo=new CustomerVo()
                .setId(customer.getId())
                .setCustomer_name(customer.getCustomerName());
        return customerVo;
    }


}
